package com.vanke.kotlin_mvp.data.local

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import com.vanke.kotlin_mvp.App
import org.jetbrains.anko.db.*

/**
 * @name Kotlin_MVP
 * @package name：com.vanke.kotlin_mvp.data.local
 * @class describe
 * @anthor shiyuchuan
 * @time 2017/8/17 10:00
 */
class TasksDbHelper(context: Context = App.instance) : ManagedSQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {


    override fun onCreate(db: SQLiteDatabase) {
        db.createTable(TasksTable.TaskEntry.TABLE_NAME, true,
                TasksTable.TaskEntry.COLUMN_NAME_ENTRY_ID to TEXT + PRIMARY_KEY,
                TasksTable.TaskEntry.COLUMN_NAME_TITLE to TEXT,
                TasksTable.TaskEntry.COLUMN_NAME_DESCRIPTION to TEXT,
                TasksTable.TaskEntry.COLUMN_NAME_COMPLETED to INTEGER)
    }

    override fun onUpgrade(db: SQLiteDatabase, old: Int, new: Int) {

    }

    companion object {
        val DB_NAME = "task.db"
        val DB_VERSION = 1
        val instance: TasksDbHelper by lazy { TasksDbHelper() }
    }

}